home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
Network
/
Ping 1.1
/
Source
/
Util.c
< prev
next >
Wrap
Text File
|
1992-04-18
|
2KB
|
110 lines
// Util.c
// Ping 1.0
//
// A neat hack © 1992 Jon Wätte (h+@nada.kth.se)
//
// Freeware - permission granted to study & distribute free of charge,
// however, you may not sell this source or any derivate thereof, nor
// may you distribute modified source or a derivate thereof.
#include "Util.h"
#define CHOOSER_NAME -16096
// Clear a block of memory
// This could be done much more efficiently by unrolling and using long moves
//
void
BlockClear ( void * ptr , long size )
{
register unsigned char * d = ptr ;
register long c = size ;
while ( c -- ) {
* ( d ++ ) = 0 ;
}
}
// Report fatal error. Gove the user a chance to try again
//
void
FatalError ( short err , char * file , int line )
{
Str32 lst ; // Line Number string
Str255 fil ; // File Name string
Str32 er ; // Error Code string
Str255 est ; // Error Text string
Handle h ;
InitCursor ( ) ;
NumToString ( err , er ) ;
NumToString ( line , lst ) ;
fil [ 0 ] = strlen ( file ) ;
BlockMove ( file , & fil [ 1 ] , fil [ 0 ] ) ;
// If you want specific errors explained, add 'Estr' resource containing
// a string, with the ID of the error number.
h = GetResource ( 'Estr' , err ) ;
est [ 0 ] = 0 ;
if ( h ) {
BlockMove ( * h , est , * * h + 1 ) ;
ReleaseResource ( h ) ;
}
ParamText ( est , er , fil , lst ) ;
if ( 1 == Alert ( 128 , NULL ) ) {
ExitToShell ( ) ;
}
}
// I don't want to include ANSI just for one lousy function...
//
long
strlen ( char * s )
{
register long c = 0 ;
register char * p = s ;
while ( * p ++ ) {
c ++ ;
}
return c ;
}
// Return the Chooser name
//
void
GetUserName ( unsigned char * theName )
{
Handle h = GetResource ( 'STR ' , CHOOSER_NAME ) ;
char state ;
if ( h && * h ) {
// Remember not to dispose or "change" system resources.
state = HGetState ( h ) ;
HLock ( h ) ;
BlockMove ( * h , theName , * * h + 1 ) ;
HSetState ( h , state ) ;
}
}
unsigned char *
AddPBuf ( unsigned char * dst , unsigned char * src )
{
BlockMove ( & src [ 1 ] , & dst [ dst [ 0 ] + 1 ] , src [ 0 ] ) ;
dst [ 0 ] += src [ 0 ] ;
return dst ;
}